package com.cqie.rbac.util;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Author 夏兵
 * @Date 2021/9/6
 */
@Data
public class Result<T> {

    @ApiModelProperty(value = "状态码")
    private String code;
    @ApiModelProperty("返回信息")
    private String msg;
    @ApiModelProperty("返回数据")
    private T data;

    private Result() {

    }

    public static Result ok() {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMessage());
        return result;
    }

    public static Result error() {
        Result result = new Result();
        result.setCode(ResultCode.ERROR.getCode());
        result.setMsg(ResultCode.ERROR.getMessage());
        return result;
    }

    public static Result unauth() {
        Result result = new Result();
        result.setCode(ResultCode.UNAUTH.getCode());
        result.setMsg(ResultCode.UNAUTH.getMessage());
        return result;
    }

    public static Result notLogin() {
        Result result = new Result();
        result.setCode(ResultCode.NOT_LOGIN.getCode());
        result.setMsg(ResultCode.NOT_LOGIN.getMessage());
        return result;
    }

    public static Result unknowServerError() {
        Result result = new Result();
        result.setCode(ResultCode.UNKNOW_SERVER_ERROR.getCode());
        result.setMsg(ResultCode.UNKNOW_SERVER_ERROR.getMessage());
        return result;
    }

    public Result<T> message(String message) {
        this.setMsg(message);
        return this;
    }

    public Result<T> code(String code) {
        this.setCode(code);
        return this;
    }

    public Result<T> data(T data) {
        this.setData(data);
        return this;
    }

}
